package com.changyinBus.common.core.domain;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.changyinBus.common.constant.UserConstants;
import com.changyinBus.common.core.domain.entity.*;
import com.changyinBus.common.utils.StringUtils;

/**
 * Treeselect树结构实体类
 *
 * @author ruoyi
 */
public class TreeSelect implements Serializable
{
    private static final long serialVersionUID = 1L;

    /** 节点ID */
    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    /** 节点名称 */
    private String label;

    private String linkUrl;

    private String icon;

    private String listIcon;

    private String backgroundImage;

    private String intro;

    /** 节点禁用 */
    private boolean disabled = false;

    /** 子节点 */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelect> children;

    public TreeSelect()
    {

    }

    public TreeSelect(SysDept dept)
    {
        this.id = dept.getDeptId();
        this.label = dept.getDeptName();
        this.disabled = StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus());
        this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysMenu menu) {
        this.id = menu.getMenuId();
        this.label = menu.getMenuName();
        this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysProdCate cate) {
        this.id = cate.getProdCateId();
        this.label = cate.getProdCateName();
        this.icon = cate.getProdCateIcon();
        this.listIcon = cate.getProdCateListIcon();
        this.backgroundImage = cate.getProdCateImage();
        this.intro = cate.getProdCateIntro();
        this.disabled = StringUtils.equals(UserConstants.DEPT_DISABLE, cate.getStatus());
        this.children = cate.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysCate cate) {
        this.id = cate.getCateId();
        this.label = cate.getCateName();
        this.backgroundImage = cate.getCateImage();
        this.intro = cate.getCateIntro();
        this.disabled = StringUtils.equals(UserConstants.DEPT_DISABLE, cate.getStatus());
        this.children = cate.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public TreeSelect(SysNavi navi) {
        this.id = navi.getNavId();
        this.label = navi.getNavName();
        String linkUrl = "";
        if(navi.getLinkUrl() != null && !navi.getLinkUrl().trim().equals("")){
            linkUrl = navi.getLinkUrl();
        }
        this.linkUrl = linkUrl;
        this.disabled = StringUtils.equals(UserConstants.DEPT_DISABLE, navi.getStatus());
        this.children = navi.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
    }

    public Long getId()
    {
        return id;
    }

    public void setId(Long id)
    {
        this.id = id;
    }

    public String getLabel()
    {
        return label;
    }

    public void setLabel(String label)
    {
        this.label = label;
    }

    public boolean isDisabled()
    {
        return disabled;
    }

    public void setDisabled(boolean disabled)
    {
        this.disabled = disabled;
    }

    public List<TreeSelect> getChildren()
    {
        return children;
    }

    public void setChildren(List<TreeSelect> children)
    {
        this.children = children;
    }
}
